package framework.mvc;

import framework.account.IAccount;
import framework.command.CommandManager;
import framework.command.CreditCommand;
import framework.command.ICommand;

public class CreditDialog extends javax.swing.JDialog {

    private IAccount account;
    private AFincoView view;

    public CreditDialog(AFincoView parent, String actionName, IAccount account) {
        super(parent);
        this.view = parent;
        this.account = account;
        setTitle(actionName);
        setModal(true);
        getContentPane().setLayout(null);
        setSize(268, 126);
        setVisible(false);
        JLabel1.setText("Name");
        getContentPane().add(JLabel1);
        JLabel1.setForeground(java.awt.Color.black);
        JLabel1.setBounds(12, 12, 48, 24);
        JLabel2.setText("Amount");
        getContentPane().add(JLabel2);
        JLabel2.setForeground(java.awt.Color.black);
        JLabel2.setBounds(12, 48, 48, 24);
        JTextField_NAME.setEditable(false);
        getContentPane().add(JTextField_NAME);
        JTextField_NAME.setBounds(84, 12, 144, 24);
        JButton_OK.setText("OK");
        JButton_OK.setActionCommand("OK");
        getContentPane().add(JButton_OK);
        JButton_OK.setBounds(36, 84, 84, 24);
        JButton_Cancel.setText("Cancel");
        JButton_Cancel.setActionCommand("Cancel");
        getContentPane().add(JButton_Cancel);
        JButton_Cancel.setBounds(156, 84, 84, 24);
        getContentPane().add(JTextField_Deposit);
        JTextField_Deposit.setBounds(84, 48, 144, 24);
        JTextField_NAME.setText(account.getAccountNo());
        SymAction lSymAction = new SymAction();
        JButton_OK.addActionListener(lSymAction);
        JButton_Cancel.addActionListener(lSymAction);
        // }}
    }


    javax.swing.JLabel JLabel1 = new javax.swing.JLabel();

    javax.swing.JLabel JLabel2 = new javax.swing.JLabel();

    javax.swing.JTextField JTextField_NAME = new javax.swing.JTextField();

    javax.swing.JButton JButton_OK = new javax.swing.JButton();

    javax.swing.JButton JButton_Cancel = new javax.swing.JButton();

    javax.swing.JTextField JTextField_Deposit = new javax.swing.JTextField();

    // }}

    class SymAction implements java.awt.event.ActionListener {
        public void actionPerformed(java.awt.event.ActionEvent event) {
            Object object = event.getSource();
            if (object == JButton_OK)
                JButtonOK_actionPerformed(event);
            else if (object == JButton_Cancel)
                JButtonCalcel_actionPerformed(event);
        }
    }

    void JButtonOK_actionPerformed(java.awt.event.ActionEvent event) {
        ICommand command = new CreditCommand(account, Float.valueOf(JTextField_Deposit.getText()));
        CommandManager.getInstance().submit(command);
        dispose();
    }

    void JButtonCalcel_actionPerformed(java.awt.event.ActionEvent event) {
        dispose();
    }
}